package com.rock.code.system.shiro.realm;//package com.rock.code.system.shiro.realm;
//
//import com.rock.code.base.domain.Constants;
//import com.rock.code.system.user.domain.TbSysLoginmsg;
//import com.rock.code.system.user.service.TbSysLoginmsgService;
//import org.apache.shiro.SecurityUtils;
//import org.apache.shiro.authc.AuthenticationInfo;
//import org.apache.shiro.authc.AuthenticationToken;
//import org.apache.shiro.authz.SimpleAuthorizationInfo;
//import org.apache.shiro.cas.CasRealm;
//
//import javax.annotation.Resource;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.concurrent.ConcurrentHashMap;
//
///**
// * 用户授权信息域
// *
// * @author coderhuang
// *
// */
//public class UserRealm extends CasRealm {
//
//	@Resource
//	private TbSysLoginmsgService tbSysLoginmsgServiceImpl;
//
//	protected final Map<String, SimpleAuthorizationInfo> roles = new ConcurrentHashMap<String, SimpleAuthorizationInfo>();
//
//    /**
//     * 1、CAS认证 ,验证用户身份
//     * 2、将用户基本信息设置到会话中
//     */
//    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) {
//
//        AuthenticationInfo authc = super.doGetAuthenticationInfo(token);
//
//        Map<String, Object> param = new HashMap<>();
//        String account = (String) authc.getPrincipals().getPrimaryPrincipal();
//        param.put("userCode", account);
//        param.put("isDelete", Constants.DELETE_N);
//
//        try {
//            List<TbSysLoginmsg> user = tbSysLoginmsgServiceImpl.queryListByParaMap(param);
//            SecurityUtils.getSubject().getSession().setAttribute("user", user.get(0));
//        } catch (Exception e){
//            e.printStackTrace();
//        }
//
//        return authc;
//    }
//
////	/**
////	 * 设置角色和权限信息
////	 */
////	@Override
////	protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
////
////		String account = (String) principals.getPrimaryPrincipal();
////		SimpleAuthorizationInfo authorizationInfo = null;
////		if (authorizationInfo == null) {
////			authorizationInfo = new SimpleAuthorizationInfo();
////			authorizationInfo.addStringPermissions(roleService.getPermissions(account));
////			authorizationInfo.addRoles(roleService.getRoles(account));
////			roles.put(account, authorizationInfo);
////		}
////
////		return authorizationInfo;
////	}
//
//}
